<?php
session_start();

include_once "<cs_name>_spec.php";
include_once "<cs_name>_mdl.php";
include_once "<cs_name>_view.php";

$maintable = '<main_table>';
// get mode
$mode = $_REQUEST['mode'];

if($mode == 'update'){

	$newvalues = CF_ParamReciever::GetSingleValue('field','value');
	$keyvalues = CF_ParamReciever::GetReqParamsPacked('project_id', 'kv', ',',false);

	$result = <cs_name>_mdl::do_update($keyvalues, $newvalues, $maintable);

	print json_encode($result);

}else if($mode == 'add'){
	$fs = new CF_FieldSpec($fieldspec);
	$ar_add_columns = $fs->GetColumnsArray('add');
	$newvalues = CF_ParamReciever::GetReqParamsByList($ar_add_columns,'',false);
	
	//$newvalues = array(0=>array('lastName'=>'NEW'));
	$result = <cs_name>_mdl::do_add($keyvalues, $newvalues, $maintable);

	header('Location: <cs_name>_ctl.php?mode=view');	

}else if($mode == 'delete'){
	$fs = new CF_FieldSpec($fieldspec);
	//$oldvalues = CF_ParamReciever::GetReqParamsByList($ar_add_columns,'OV_',false);
	$ar_key_columns = $fs->GetColumnsArray('key');
	$keyvalues = CF_ParamReciever::GetReqParamsByList($ar_key_columns,'',false);

	$result = <cs_name>_mdl::do_delete($keyvalues,$maintable);
	header('Location: <cs_name>_ctl.php?mode=view');
	
}else{

	$fs = new CF_FieldSpec($fieldspec);

	$filters =  CF_FilterReciever::get_filters($fieldspec);
	//$params = CF_FilterQueryPdo::filter_parameters($filters);
	
	$set =  CF_FilterReciever::filters_to_set($filters);
	
	$order_column = $_REQUEST['_order'];
	$order_dir = $_REQUEST['_dir'];
	if(empty($order_dir)){
		$order_dir = 'ASC';
	}
	if(!empty($order_column)){
		$order = array($order_column=>$order_dir);
	}

	$records = <cs_name>_mdl::get_records($filters, $order);
	
	
	$ar_columns = $fs->GetColumnsArray('listquery');

	$ar_lookuplists = <cs_name>_mdl::get_lookuplists($fs,$ar_columns,$set);

	show_listview($records,$fieldspec,$ar_lookuplists,$filters);
	
}


?>